package com.stylefeng.guns.modular.device.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.DeviceInfo;
import com.stylefeng.guns.modular.device.service.IDeviceInfoService;

/**
 * deviceInfo控制器
 *
 * @author fengshuonan
 * @Date 2018-11-13 17:24:01
 */
@Controller
@RequestMapping("/deviceInfo")
public class DeviceInfoController extends BaseController {

    private String PREFIX = "/device/deviceInfo/";

    @Autowired
    private IDeviceInfoService deviceInfoService;

    /**
     * 跳转到deviceInfo首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "deviceInfo.html";
    }

    /**
     * 跳转到添加deviceInfo
     */
    @RequestMapping("/deviceInfo_add")
    public String deviceInfoAdd() {
        return PREFIX + "deviceInfo_add.html";
    }

    /**
     * 跳转到修改deviceInfo
     */
    @RequestMapping("/deviceInfo_update/{deviceInfoId}")
    public String deviceInfoUpdate(@PathVariable Integer deviceInfoId, Model model) {
        DeviceInfo deviceInfo = deviceInfoService.selectById(deviceInfoId);
        model.addAttribute("item",deviceInfo);
        LogObjectHolder.me().set(deviceInfo);
        return PREFIX + "deviceInfo_edit.html";
    }

    /**
     * 获取deviceInfo列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        EntityWrapper<DeviceInfo> wrapper = new EntityWrapper<>();
        wrapper.like("device_name",condition);
        return deviceInfoService.selectList(wrapper);
    }

    /**
     * 新增deviceInfo
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(DeviceInfo deviceInfo) {
        deviceInfoService.insert(deviceInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除deviceInfo
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer deviceInfoId) {
        deviceInfoService.deleteById(deviceInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改deviceInfo
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(DeviceInfo deviceInfo) {
        deviceInfoService.updateById(deviceInfo);
        return SUCCESS_TIP;
    }

    /**
     * deviceInfo详情
     */
    @RequestMapping(value = "/detail/{deviceInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("deviceInfoId") Integer deviceInfoId) {
        return deviceInfoService.selectById(deviceInfoId);
    }
}
